*****************************************************************
*																*
*				Title: 3_regressions_paper		 	 	   	    *		
*															    *
*****************************************************************

/*  ================================  NOTES  ================================

+ PURPSOSE:
	
	In this do-file we run regressions for the paper sector and output the regressions' results
	
		
+ Inputs:

		* 1. panel_paper.dta
			
==============================  TOP MATTER ==============================*/


************** END HEADER **************


	*DATA
	global proc_data "`pdir'/data"
	global output "`pdir'/outputs/main_paper"

********************************** END HEADER **********************************

use "$proc_data/panel_paper.dta", clear



******************************************************************
**********************      FIGURES			**********************
******************************************************************


************	Figure 1 (Panel C). *******************************************
*** Changes in the Productivity Distributions in Paper	 	***********

 twoway (kdensity logYoverL_real if year == 1794, bwidth(0.2) lcolor(gs6) lpattern(dash) lwidth(thick)) ///
 (kdensity logYoverL_real if year == 1840, bwidth(0.2) lcolor(navy) lpattern(solid) lwidth(thick)), ///
 ytitle(Kernel density, size(large)) xtitle(ln(Output per worker), size(large)) xscale(range(2 10)) xlabel(2(2)10, labsize(medlarge)) ylabel(, labsize(medlarge)) ///
 legend(order(1 "1794" 2 "1840") position(9) ring(0) cols(1) size(large))  scheme(s1color)
graph export "$output/Figures/Figure_1C.eps", replace
graph export "$output/Figures/Figure_1C.pdf", replace
	


	
************	Figure 2 (Panel C). *******************************************
*** Productivity Growth at Different Quantiles of the Distribution 	***********

forv i=10(10)90{
	preserve	
		xi:qreg logYoverL_real_pa i.year, quantile(`i') vce(robust)
		est store est`i'
	restore
}

coefplot est10 || est20 || est30 || est40 || est50 || est60 || est70 || est80 || est90, keep(_I*) vertical pstyle(p7) color(black) ciopts(color(black) recast(rcap)) citop legend(off) xtitle("Decile", size(large)) ytitle(Avg annual growth rate (%), size(large))  ylabel(0 (1) 4, labsize(medlarge))  scheme(s1color) bycoefs bylabels("0.1" "0.2" "0.3" "0.4" "0.5" "0.6" "0.7" "0.8" "0.9")

graph export "$output/Figures/Figure_2C.eps", replace
graph export "$output/Figures/Figure_2C.pdf", replace
	
	
	
******************************************************************
**********************      TABLES			**********************
******************************************************************
	
	
	
************	Table 1 (Panel C). ***********************************
*** Annual Productivity Growth (in %) at Different Quantiles of the Distribution	


estimates clear	
quietly{
	eststo: xi:reg logYoverL_real_pa i.year,  vce(robust)
	local N_obs = e(N)
	eststo: xi:qreg logYoverL_real_pa i.year, quantile(10) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year, quantile(25) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year, quantile(50) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year, quantile(75) vce(robust)
	eststo: xi:qreg logYoverL_real_pa i.year, quantile(90) vce(robust)
	
}
*
estout using "$output/Tables/Table_1C.tex", replace label drop(_cons) order($show ) ///
rename (_Iyear_1840 "Paper milling\ (1794-1840)")  ///
	mlabels(, title prefix(%) begin(%)) postfoot("\addlinespace[0.25cm] ") end("& `N_obs'" "\\[-0.15cm]")  varlabels(, end("\addlinespace[0.00cm] ")) ///
	cells(b(fmt(3) star) se(fmt(3) par)) starlevels($^{*}$ 0.1 $^{**}$ 0.05 $^{***}$ 0.01) style(tex) collabels(none) 	

*Redundancy in reported number of observations in the last column is fixed by hand after generating the table		


